import { action } from 'mobx';

import ListBaseStore from './ListBaseStore';
import * as CollectApis from '../apis/collect';
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;

/**
 * 收藏的帖子Store
 */
export default class CollectStore extends ListBaseStore {
	constructor() {
		super();

		this.title = getLabel(382666, '收藏的帖子');
	}

	@action doInit = () => {
		this.doBaseInit();
    this.doTableLoading(); // 初始化列表
    this.initConditionDatas(); // 初始化高级搜索区域
	}
	// 加载列表数据
	@action doTableLoading = (params) => {
		this.showLoading(true);
		let resultParams = this.getFormParams();
		let commonParams = {};
		resultParams = { ...resultParams, ...commonParams, ...params };

		CollectApis.getCoworkCollectList(resultParams).then(
			(result) => {
				const sessionkey = result.sessionkey;
				this.sessionkey = sessionkey;
				this.comsWeaTableStore.getDatas(sessionkey, 1);

				this.showLoading(false);
			},
		);
	}

	// 初始化收藏的帖子页面查询条件
	@action initConditionDatas = (params) => {
		CollectApis.getCoworkCollectShareCondition(params).then(
			(result) => {
				this.conditioninfo = result.conditioninfo;

				this.initFormFields(this.conditioninfo); // 一定要先初始化initFormFields表单对象
			},
		);
	}

	// 取消收藏
	@action cancelCoworkCollect = (params, callback) => {
		let resultParams = {
			collectIds: params.collectIds,
		};
		CollectApis.cancelCoworkCollect(resultParams).then(
			() => {
				if (callback && typeof callback === 'function') {
					callback();
				}
			},
		);
	}
}
